package com.xuan.yrmanage.service;


import com.xuan.yrmanage.common.response.CommonCode;
import com.xuan.yrmanage.common.response.QueryResult;
import com.xuan.yrmanage.common.response.ResponseResult;
import com.xuan.yrmanage.dao.PermissionMapper;
import com.xuan.yrmanage.domain.Permission;
import com.xuan.yrmanage.domain.request.QueryBean;
import com.xuan.yrmanage.domain.request.QueryPageBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * FileName: PermissionService
 * Author:   xuan zongjun
 * Date:     2020/3/17 13:52
 * Description: 权限服务层
 */

@Service
public class PermissionService {
    @Autowired
    private PermissionMapper permissionMapper;

    /**
     * 获取权限列表
     * @param queryPageBean 条件
     * @return
     */
    public ResponseResult findAll(QueryPageBean queryPageBean) {
        int pageIndex =queryPageBean.getPageIndex();
        int pageSize = queryPageBean.getPageSize();
        String queryString = queryPageBean.getQueryString();
        //获取列表
        List<Permission> list = permissionMapper.findAll( pageIndex, pageSize, queryString );
        int count = permissionMapper.getCount( queryString );
        QueryResult<Permission> queryResult = new QueryResult<>();
        queryResult.setList( list );
        queryResult.setTotal( count );
        return new ResponseResult( CommonCode.SUCCESS,queryResult);



    }

    /**
     * 通过ID查询权限
     * @param id
     * @return
     */
    public ResponseResult findById(String id) {

        Permission permission = permissionMapper.findById(id);
        return new ResponseResult( CommonCode.SUCCESS,permission);
    }

    /**
     * 添加
     * @param permission
     * @return
     */
    public ResponseResult add(Permission permission) {
        permissionMapper.add(permission);
        return new ResponseResult( CommonCode.SUCCESS);
    }

    /**
     * 修改
     * @param permission
     * @return
     */
    public ResponseResult edit(Permission permission) {
        permissionMapper.edit(permission);
        return new ResponseResult( CommonCode.SUCCESS);

    }
}
